home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / printing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-02  |  3.5 KB  |  200 lines

  1.  
  2. /*⌐ Copyright 1988-1991 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletinternal.h"
  6. #include "ops.h"
  7. #include "quickdraw.h"
  8. #include "appletmain.h"
  9. #include "printing.h"
  10.  
  11.  
  12. static disposeprintinfo (void) {
  13.  
  14.     disposehandle ((Handle) app.printinfo.printhandle);
  15.     
  16.     clearbytes (&app.printinfo, longsizeof (app.printinfo));
  17.     } /*disposeprintinfo*/
  18.  
  19.  
  20. static boolean checkprinterror (void) {
  21.     
  22.     /*
  23.     returns false if there was a print error.
  24.     */
  25.     
  26.     short x;
  27.     bigstring bserror, bs;
  28.     
  29.     x = PrError ();
  30.     
  31.     if (x == noErr) /*no error, keep going*/
  32.         return (true);
  33.     
  34.     if (x != iPrAbort) 
  35.         appalert ("\pPrinting error.");
  36.     
  37.     return (false); /*there was an error*/
  38.     } /*checkprinterror*/
  39.  
  40.  
  41. static copyprintinfo (void) {
  42.     
  43.     Rect r;
  44.     
  45.     r = app.printinfo.paperrect = (**(THPrint) app.printinfo.printhandle).prInfo.rPage;
  46.     
  47.     app.printinfo.vpagepixels = r.bottom - r.top; 
  48.     } /*copyprintinfo*/
  49.  
  50.  
  51. boolean initprint (void) {
  52.     
  53.     Handle h;
  54.     Rect r;
  55.     
  56.     clearbytes (&app.printinfo, longsizeof (app.printinfo));
  57.     
  58.     if (!newclearhandle (longsizeof (TPrint), &h))
  59.         return (false);
  60.     
  61.     app.printinfo.printhandle = h; /*copy into print record*/
  62.     
  63.     PrOpen (); /*initialize the Mac print manager*/
  64.     
  65.     if (!checkprinterror ())
  66.         goto error;
  67.     
  68.     PrintDefault ((THPrint) app.printinfo.printhandle); /*set default print record*/
  69.     
  70.     PrClose (); /*shouldn't leave print resources open all the time*/
  71.     
  72.     if (!checkprinterror ()) 
  73.         goto error;
  74.     
  75.     copyprintinfo (); /*copies fields from handle into record*/
  76.     
  77.     return (true);
  78.     
  79.     error:
  80.     
  81.     disposeprintinfo ();
  82.         
  83.     return (false);
  84.     } /*initprint*/
  85.  
  86.  
  87. static boolean pagesetupvisit (hdlappwindow appwindow) {
  88.  
  89.     setappwindow (appwindow);
  90.     
  91.     (*app.pagesetupcallback) ();
  92.     } /*pagesetupvisit*/
  93.  
  94.  
  95. boolean pagesetup (void) {
  96.     
  97.     PrOpen ();
  98.     
  99.     if (!checkprinterror ()) 
  100.         return (false);
  101.     
  102.     PrValidate ((THPrint) app.printinfo.printhandle);
  103.     
  104.     PrStlDialog ((THPrint) app.printinfo.printhandle);
  105.     
  106.     PrClose ();
  107.     
  108.     if (!checkprinterror ())
  109.         return (false);
  110.     
  111.     copyprintinfo (); /*copies fields from handle into record*/
  112.     
  113.     visitappwindows (&pagesetupvisit);
  114.     } /*pagesetup*/
  115.  
  116.  
  117. boolean printappwindow (hdlappwindow appwindow, boolean fldialog) {
  118.     
  119.     TPPrPort printport;
  120.     TPrStatus printstatus;
  121.     short i;
  122.     register boolean fl;
  123.     
  124.     setappwindow (appwindow);
  125.     
  126.     PrOpen ();
  127.     
  128.     if (!checkprinterror ())
  129.         return (false);
  130.     
  131.     fl = false; /*until sucessfull print, this is return value*/
  132.     
  133.     if (fldialog) {
  134.         
  135.         if (!PrJobDialog ((THPrint) app.printinfo.printhandle))
  136.             goto exit;
  137.             
  138.         serviceeventqueue (); /*update all dirtied windows*/
  139.         }
  140.     else
  141.         PrValidate ((THPrint) app.printinfo.printhandle);
  142.     
  143.     watchcursor ();
  144.     
  145.     copyprintinfo ();
  146.     
  147.     (*app.openprintcallback) (); /*fills in fields of printinfo record*/
  148.     
  149.     pushmacport (nil); /*save current port on stack*/
  150.     
  151.     printport = PrOpenDoc ((THPrint) app.printinfo.printhandle, nil, nil);
  152.     
  153.     for (i = 1; i <= app.printinfo.ctpages; i++) { /*print one page*/
  154.         
  155.         if (!serviceeventqueue ()) /*user must have selected quit or something like that*/
  156.             PrSetError (iPrAbort);
  157.             
  158.         if (PrError () != noErr)
  159.             break;
  160.         
  161.         PrOpenPage (printport, nil);
  162.         
  163.         if (PrError () == noErr) {
  164.             
  165.             SetFractEnable (true);
  166.             
  167.             fl = (*app.printpagecallback) (i);
  168.             
  169.             SetFractEnable (false);
  170.             }
  171.         
  172.         PrClosePage (printport);
  173.         
  174.         if (!fl)
  175.             break;
  176.         } /*for*/
  177.     
  178.     PrCloseDoc (printport);
  179.     
  180.     if (fl) {
  181.         
  182.         if (PrError () == noErr)
  183.             PrPicFile ((THPrint) app.printinfo.printhandle, nil, nil, nil, &printstatus);
  184.         
  185.         fl = checkprinterror ();
  186.         }
  187.     
  188.     popmacport ();
  189.     
  190.     exit:
  191.     
  192.     (*app.closeprintcallback) ();
  193.     
  194.     PrClose ();
  195.     
  196.     return (fl);
  197.     } /*printappwindow*/
  198.  
  199.  
  200.